package edu.scau.divineplace.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import edu.scau.divineplace.entity.dos.BanWordDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotBlank;

/**
 * @Author: x1aolone
 * @Date: 2021/1/14 16:13
 */
@Service
public class BanWordService {

    @Autowired
    private ImportMapperService importMapperService;

    /**
     * 判断comment里面是否有违禁词
     * @param comment 评论
     * @return
     */
    public Boolean judge(@NotBlank String comment) {
        QueryWrapper<BanWordDO> query = Wrappers.<BanWordDO>query()
                .select("id")
                .gt("POSITION(word in '" + comment + "')", 0);
        Integer count = importMapperService.banWordMapper.selectCount(query);
        return count > 0;
    }

}
